﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Linq;

using Newtonsoft.Json;


namespace JSONCommon
{
    

    public class JSON_Converter : IDisposable
    {


        void IDisposable.Dispose() { }

        /// <summary>
        /// Json문자열을 DataSet으로 변환
        /// </summary>
        /// <param name="JsonString">변환할 Json문자열</param>
        /// <returns>DataSet</returns>
        public DataSet JsonStringToDataSet(string JsonString)
        {
            DataSet ds = null;

            try
            {   
                ds = JsonConvert.DeserializeObject<DataSet>(JsonString);
            }
            catch (Exception ex)
            {
                ds = null;
            }
            return ds;
        }


        /// <summary>
        /// DataSet을 Json문자열로 변환
        /// </summary>
        /// <param name="ds">변환할 DatsSet</param>
        /// <returns>Json문자열</returns>
        public string DataSetToJson(DataSet ds)
        {
            string sJson = string.Empty;

            try
            {
                sJson = JsonConvert.SerializeObject(ds);
            }
            catch (Exception ex)
            {
                sJson = "";
            }

            return sJson;
        }

        
    }

    
}
